﻿using System;
using System.Data;
using System.Collections.Generic;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;

using LMD.Constant;

namespace LMD.Lib.Controls
{
    public static class CustomControls
    {
        public static String Create_ComboBox(DataTable dtSource, String sxControlId,
            String sxControlName, String sxSelectedValue, String sxKeyFieldName, String sxValueFieldName)
        {
            return Create_ComboBox(dtSource, sxControlId, sxControlName, sxSelectedValue, sxKeyFieldName,
                sxValueFieldName, String.Empty, false);
        }
        public static String Create_ComboBox(DataTable dtSource, String sxControlId, String sxControlName, 
            String sxSelectedValue, String sxKeyFieldName, String sxValueFieldName, String sxCustomAction, 
            bool IsNeedEmptyItems)
        {
            String sxOptions = String.Empty;

            if (IsNeedEmptyItems)
            {
                sxOptions += "<option value=\"\">---</option>";
            }

            for (int i = 0; i < dtSource.Rows.Count; i++)
            {
                String key = dtSource.Rows[i][sxKeyFieldName].ToString();
                String value = dtSource.Rows[i][sxValueFieldName].ToString();
                sxOptions += String.Format("<option value=\"{0}\" {2}>{1}</option>",
                    key.ReplaceQuotes(),
                    value,
                    key == sxSelectedValue || value == sxSelectedValue ? "selected=\"selected\"" : String.Empty);
            }

            String sxOutput = String.Format(
                  "<select id=\"{0}\" {3} name=\"{1}\">{2}</select>",
                  sxControlId.ReplaceQuotes(),
                  sxControlName.ReplaceQuotes(),
                  sxOptions,
                  String.IsNullOrEmpty(sxCustomAction) ?
                    String.Empty : String.Format("onchange=\"{0}\"", sxCustomAction));

            return sxOutput;
        }
                
        public static String Create_ComboBox(String sxControlId, String sxControlName,
            Dictionary<String, String> dicOptions, String sxSelectedValue)
        {
            return Create_ComboBox(sxControlId, sxControlName, dicOptions, sxSelectedValue, null);
        }

        public static String Create_ComboBox(String sxControlId, String sxControlName,
            Dictionary<String, String> dicOptions, String sxSelectedValue, String sxCustomAction)
        {
            String sxOptions = String.Empty;

            foreach (KeyValuePair<String, String> item in dicOptions)
            {
                sxOptions += String.Format("<option value=\"{0}\" {2}>{1}</option>",
                    item.Key.ReplaceQuotes(),
                    item.Value,
                    item.Key == sxSelectedValue || item.Value == sxSelectedValue ? "selected=\"selected\"" : String.Empty);
            }

            String sxOutput = String.Format(
                "<select id=\"{0}\" {3} name=\"{1}\">{2}</select>",
                sxControlId.ReplaceQuotes(),
                sxControlName.ReplaceQuotes(),
                sxOptions,
                String.IsNullOrEmpty(sxCustomAction) ? 
                    String.Empty : String.Format("onchange=\"{0}\"", sxCustomAction)
                  );

            return sxOutput;
        }

        public static String Create_OTFComboBox(String sxControlId, String sxLOVName, String sxSelectedValue, String sxSelectedId)
        {
            return Create_OTFComboBox(sxControlId, sxLOVName, sxSelectedValue, sxSelectedId, TextboxType.FreeText);
        }
        public static String Create_OTFComboBox(String sxControlId, String sxLOVName, String sxSelectedValue, String sxSelectedId, TextboxType tpTextbox)
        {
            return Create_OTFComboBox(sxControlId, sxLOVName, sxSelectedValue, sxSelectedId, tpTextbox, null, null);
        }
        public static String Create_OTFComboBox(String sxControlId, String sxLOVName, String sxSelectedValue, String sxSelectedId,
            TextboxType tpTextbox, String sxCustomParameter, String sxCustomOnChooseAction)
        {
            return Create_OTFComboBox(sxControlId, sxLOVName, sxSelectedValue, sxSelectedId, tpTextbox, sxCustomParameter, sxCustomOnChooseAction, false);
        }
        public static String Create_OTFComboBox(String sxControlId, String sxLOVName, String sxSelectedValue, String sxSelectedId, 
            TextboxType tpTextbox, String sxCustomParameter, String sxCustomOnChooseAction, bool IsMandatory)
        {
            String sxOutput = String.Format(
                "<div class=\"lov_container\">" +
                    "<input type=\"text\" id=\"{1}_{0}\" name=\"{1}\" value=\"{2}\" autocomplete=\"off\"" +
                        " onkeyup=\"drawLOV('{0}');\" onfocus=\"focusLOV('{0}');\"" +
                        " onblur=\"withdrawLOV('{0}','{10}');\" onkeypress=\"enterLOV('{0}','{10}');\"/>{11}" +
                    "<br/><div id=\"{7}_{0}\" name=\"{7}\" class=\"lov_panel\"></div>" +
                    "<input type=\"hidden\" id=\"{3}_{0}\" value=\"{4}\"/>" +
                    "<input type=\"hidden\" id=\"{5}_{0}\" value=\"{6}\"/> {8}{9}" +
                "</div>",
                sxControlId.ReplaceQuotesForJS(),
                KControl.OTF_DROPDOWN_ID,
                sxSelectedValue.ReplaceQuotes(),
                KControl.OTF_HIDDENFIELD_ID,
                sxSelectedId.ReplaceQuotes(),
                KControl.OTF_HIDDENFIELD_LOVNAME,
                sxLOVName.ReplaceQuotes(),
                KControl.OTF_CONTENT_ID,
                tpTextbox != TextboxType.Empty ?
                    String.Format(
                        "<input type=\"hidden\" id=\"{1}_{0}\" value=\"{2}\"/>", sxControlId.ReplaceQuotes(),
                        KControl.OTF_HIDDENFIELD_LOVDATATYPE, ((int)tpTextbox).ToString()) :
                    String.Empty,
                !String.IsNullOrEmpty(sxCustomParameter) ?
                    String.Format(
                        "<input type=\"hidden\" id=\"{1}_{0}\" value=\"{2}\"/>", sxControlId.ReplaceQuotes(),
                        KControl.OTF_HIDDENFIELD_LOVCUSTOMPARAM, sxCustomParameter.ReplaceQuotes()) :
                    String.Empty,
                String.IsNullOrEmpty(sxCustomOnChooseAction) ? String.Empty : sxCustomOnChooseAction, 
                IsMandatory ?
                    String.Format(
                        "* <input type=\"hidden\" id=\"{1}_{0}\" value=\"{2}\"/>", sxControlId.ReplaceQuotes(),
                        KControl.MANDATORY_ID, KGlobal.YES) :
                    String.Empty
                );

            return sxOutput;
        }

        public static String Create_LOVDrawer(String sxControlId, DataTable dtSource, int iIndex, int iPageSize,
            String sxFilter, String sxIDField, String sxLabelField, bool bCanAdd)
        {
            return Create_LOVDrawer(sxControlId, dtSource, iIndex, iPageSize, sxFilter, 
                sxIDField, sxLabelField, String.Empty, bCanAdd);
        }
        public static String Create_LOVDrawer(String sxControlId, DataTable dtSource, int iIndex, int iPageSize,
            String sxFilter, String sxIDField, String sxLabelField, String sxCustomOnChooseAction, bool bCanAdd)
        {
            DataTable dtFiltered = new DataView(dtSource,
                String.Format("{0} like '%{1}%'", sxLabelField, sxFilter.ReplaceQuotes()),
                String.Format("{0} asc", sxLabelField),
                DataViewRowState.CurrentRows).ToTable();

            DataTable dtExist = new DataView(dtSource,
                String.Format("{0} = '{1}'", sxLabelField, sxFilter.ReplaceQuotes()),
                String.Format("{0} asc", sxLabelField),
                DataViewRowState.CurrentRows).ToTable();

            String sxOutput = String.Empty;
            int iStart = iIndex * iPageSize;
            int iCount = dtFiltered.Rows.Count;
            //int iPageCount = (int)(Math.Ceiling((double)(iCount / iPageSize))); // I DONT KNOW WHY THIS DIDN'T WORK, THE VALUE ON THE WATCH MODE IS EXACTLY RIGHT, BUT ON CODE EXECUTION IT BECAME SUCK!!!
            int iPageCount = iCount / iPageSize;
            if (iCount % iPageSize > 0)
            {
                iPageCount++;
            }

            if (iCount == 0)
            {
                sxOutput += "<div class=\"lovnull\">NO MATCHES RESULT</div>";
            }

            String sxMatchId = String.Empty;
            String sxMatchValue = String.Empty;

            int iMatch = 0;

            for (int i = iStart; i < iStart + iPageSize; i++)
            {
                if (i > iCount - 1) break;
                DataRow dr = dtFiltered.Rows[i];

                String sxValue = dr[sxLabelField].ToString();
                String sxId = dr[sxIDField].ToString().ReplaceQuotes();
                bool IsExactMatch = sxValue.Trim().ToUpper() == sxFilter.ToUpper();
                //String sxClass = (IsExactMatch && iMatch == 0) ? "lovitem_match" : "lovitem";
                String sxClass = "lovitem";
                iMatch += IsExactMatch ? 1 : 0;

                sxOutput += String.Format(
                    "<div class=\"{4}\" name=\"lovitem_{0}\" id=\"lovitem_{0}_{1}\" " + 
                        "onclick=\"chooseLOV('{0}', '{1}', '{2}', '{3}');\">{5}</div>",
                    sxControlId.ReplaceQuotes(), 
                    sxId.ReplaceQuotes(), 
                    sxValue.ReplaceQuotesForJS(), 
                    sxCustomOnChooseAction.ReplaceQuotes(), 
                    sxClass,
                    sxValue.ReplaceQuotes());

                if (IsExactMatch)
                {
                    sxMatchId = sxId;
                    sxMatchValue = sxValue;
                }
            }

            //if (!String.IsNullOrEmpty(sxMatchId) || !String.IsNullOrEmpty(sxMatchValue))
            //{
            //    sxOutput += String.Format("<input type=\"hidden\" id=\"lovmatch_{0}\" value=\"{1}{3}{2}\" />",
            //        sxControlId.ReplaceQuotes(), sxMatchId.ReplaceQuotes(), sxMatchValue.ReplaceQuotes(), KGlobal.DELIMITER);
            //}

            if (dtExist.Rows.Count == 0 && !String.IsNullOrEmpty(sxFilter) && bCanAdd)
            {
                sxOutput += String.Format(
                    "<div id=\"lovadd_{1}\" class=\"lovadd\" onclick=\"add2LOV('{1}', '{0}');\">" +
                    "<img src=\"images/lov_new.png\"/>" +
                    " add \"{0}\" " +
                    "<img src=\"images/lov_new.png\"/>" +
                    "</div>",
                    sxFilter.ReplaceQuotesForJS(),
                    sxControlId.ReplaceQuotesForJS());
            }

            if (iPageSize < iCount)
            {
                sxOutput += CustomControls.Create_LOVPager(sxControlId, iIndex, iPageCount);
            }

            return "<span>" + sxOutput + "</span>";
        }

        public static String Create_LOVTabular(String sxControlId, DataTable dtSource, int iIndex, int iPageSize,
            String sxFilter, String sxIDField, String sxLabelField, bool bCanAdd)
        {
            return Create_LOVTabular(sxControlId, dtSource, iIndex, iPageSize,
                sxFilter, sxIDField, sxLabelField, String.Empty, bCanAdd);
        }

        public static String Create_LOVTabular(String sxControlId, DataTable dtSource, int iIndex, int iPageSize,
            String sxFilter, String sxIDField, String sxLabelField, String sxCustomOnChooseAction, bool bCanAdd)
        {
            DataTable dtFiltered = new DataView(dtSource,
                String.Format("{0} like '%{1}%'", sxLabelField, sxFilter),
                String.Format("{0} asc", sxLabelField),
                DataViewRowState.CurrentRows).ToTable();

            DataTable dtExist = new DataView(dtSource,
                String.Format("{0} = '{1}'", sxLabelField, sxFilter),
                String.Format("{0} asc", sxLabelField),
                DataViewRowState.CurrentRows).ToTable();

            String sxOutput = String.Empty;
            int iStart = iIndex * iPageSize;
            int iCount = dtFiltered.Rows.Count;
            //int iPageCount = (int)(Math.Ceiling((double)(iCount / iPageSize))); // I DONT KNOW WHY THIS DIDN'T WORK, THE VALUE ON THE WATCH MODE IS EXACTLY RIGHT, BUT ON CODE EXECUTION IT BECAME SUCK!!!
            int iPageCount = iCount / iPageSize;
            if (iCount % iPageSize > 0)
            {
                iPageCount++;
            }

            if (iCount == 0)
            {
                sxOutput += "<div class=\"lovnull\">NO MATCHES RESULT</div>";
                //return "<span>" + sxOutput + "</span>";
            }

            String sxMatchId = String.Empty;
            String sxMatchValue = String.Empty;

            sxOutput += "<table class=\"m_lovTable\" cellspacing=\"0\">";

            sxOutput += "<tr class=\"m_th\">";

            foreach (DataColumn dc in dtFiltered.Columns)
            {
                if (dc.ColumnName.ToUpper() == sxIDField.ToUpper())
                    continue;

                sxOutput += String.Format("<td>{0}</td>", dc.ColumnName);
            }

            sxOutput += "</tr>";

            int iMatch = 0;

            for (int i = iStart; i < iStart + iPageSize; i++)
            {
                if (i > iCount - 1) break;
                DataRow dr = dtFiltered.Rows[i];

                String sxValue = dr[sxLabelField].ToString();
                String sxId = dr[sxIDField].ToString();

                bool IsExactMatch = sxValue.Trim().ToUpper() == sxFilter.ToUpper();
                //String sxClass = (IsExactMatch && iMatch == 0) ? "lovitem_match" : (i % 2 == 0) ? "m_tr1" : "m_tr2";
                String sxClass = (i % 2 == 0) ? "m_tr1" : "m_tr2";
                iMatch += IsExactMatch ? 1 : 0;

                sxOutput += String.Format(
                    "<tr class=\"{4}\" name=\"lovitem_{0}\" id=\"lovitem_{0}_{1}\" " + 
                        " onclick=\"chooseLOV('{0}', '{1}', '{2}','{3}');\">",
                    sxControlId.ReplaceQuotesForJS(), 
                    sxId.ReplaceQuotesForJS(),
                    sxValue.ReplaceQuotesForJS(),
                    sxCustomOnChooseAction.ReplaceQuotesForJS(), 
                    sxClass);

                foreach (DataColumn dc in dtFiltered.Columns)
                {
                    if (dc.ColumnName.ToUpper() == sxIDField.ToUpper())
                        continue;

                    if (dc.ColumnName.ToUpper() == sxLabelField.ToUpper())
                    {
                        sxOutput += String.Format("<td class=\"m_bold\">{0}</td>", dr[dc.ColumnName].ToString());
                    }
                    else
                    {
                        sxOutput += String.Format("<td>{0}</td>", dr[dc.ColumnName].ToString());
                    }
                }

                sxOutput += "</tr>";


                if (IsExactMatch)
                {
                    sxMatchId = sxId;
                    sxMatchValue = sxValue;
                }
            }
            sxOutput += "</table>";

            //if (!String.IsNullOrEmpty(sxMatchId) || !String.IsNullOrEmpty(sxMatchValue))
            //{
            //    sxOutput += String.Format("<input type=\"hidden\" id=\"lovmatch_{0}\" value=\"{1}{3}{2}\" />",
            //        sxControlId.ReplaceQuotes(), sxMatchId.ReplaceQuotes(), sxMatchValue.ReplaceQuotes(), KGlobal.DELIMITER);
            //}

            if (dtExist.Rows.Count == 0 && !String.IsNullOrEmpty(sxFilter) && bCanAdd)
            {
                sxOutput += String.Format(
                    "<div id=\"lovadd_{1}\" class=\"lovadd\" onclick=\"add2LOV('{1}', '{0}');\">" +
                    "<img src=\"images/lov_new.png\"/>" +
                    " add \"{0}\" " +
                    "<img src=\"images/lov_new.png\"/>" +
                    "</div>",
                    sxFilter.ReplaceQuotesForJS(),
                    sxControlId.ReplaceQuotesForJS());
            }

            if (iPageSize < iCount)
            {
                sxOutput += CustomControls.Create_LOVPager(sxControlId, iIndex, iPageCount);
            }

            return "<span>" + sxOutput + "</span>";
        }

        public static String Create_LOVPager(String sxControlId, int iIndex, int iPageCount)
        {
            String sxOutput = String.Empty;

            if (iIndex > 0)
            {
                sxOutput += String.Format(
                    "<a href=\"javascript:delayLOV('{0}','0');\" class=\"lnk\">first</a>", sxControlId.ReplaceQuotesForJS());
            }

            int iStart = iIndex - 3;
            int iEnd = iIndex + 3;

            int iTempStart = 0;
            int iTempEnd = 0;

            if (iStart < 0)
            {
                iTempEnd -= iStart;
            }

            if (iEnd > iPageCount - 1)
            {
                iTempStart -= iPageCount - 1 - iEnd;
            }

            iStart -= iTempStart;
            iEnd += iTempEnd;

            for (int i = iStart; i <= iEnd; i++)
            {
                if (i < 0 || i >= iPageCount) continue;

                if (i == iIndex)
                {
                    sxOutput += "&nbsp[" + (i + 1).ToString() + "]&nbsp";
                }
                else
                {
                    sxOutput += String.Format("<a href=\"javascript:delayLOV('{0}','{1}');\" class=\"lnk\">{2}</a>",
                        sxControlId.ReplaceQuotesForJS(), i.ToString(), (i + 1).ToString());
                }
            }

            if (iIndex < iPageCount)
            {
                sxOutput += String.Format("<a href=\"javascript:delayLOV('{0}','{1}');\" class=\"lnk\">last</a>",
                    sxControlId.ReplaceQuotesForJS(), (iPageCount - 1).ToString());
            }

            sxOutput = String.Format(
                "<div class=\"lovpager\">" +
                "{0}" +
                "<br/>page {1} of {2}" +
                "</div>",
                sxOutput,
                (iIndex + 1).ToString(),
                iPageCount.ToString());

            return sxOutput;
        }

        public static String Create_AlphabetLink(String sxURL, String sxVar, String sxCurrentChar)
        {
            String sxOutput = "<div class=\"linkbar\">";
            char[] base26Chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".ToCharArray();

            sxOutput += String.Format(
                "<a class=\"lnk\" href=\"{0}\">{1}</a>", sxURL, "ALL");

            foreach (char ch in base26Chars)
            {
                if (ch.ToString() == sxCurrentChar.ToUpper())
                {
                    sxOutput += String.Format(
                        " | <strong>{0}</strong>", ch);
                }
                else
                {
                    sxOutput += String.Format(
                        " | <a class=\"lnk\" href=\"{0}?{1}={2}\">{2}</a>", sxURL, sxVar, ch);
                }
            }

            sxOutput += "</div>";

            return sxOutput;
        }

        public static String Create_CategoryLink(String sxURL, String sxVar, List<String> lsCategories, String sxCurrentCategory)
        {
            String sxOutput = "<div class=\"linkbar\">";

            sxOutput += String.Format(
                "<a class=\"lnk\" href=\"{0}?{1}=\">{2}</a>", sxURL, sxVar, "ALL");

            foreach (String cat in lsCategories)
            {
                if (cat.ToUpper() == sxCurrentCategory.ToUpper())
                {
                    sxOutput += String.Format(
                        " | <strong>{0}</strong>", cat);
                }
                else
                {
                    sxOutput += String.Format(
                        " | <a class=\"lnk\" href=\"{0}?{1}={2}\">{3}</a>", sxURL, sxVar, cat.EscapeForURL(), cat);
                }
            }

            sxOutput += "</div>";

            return sxOutput;
        }

        public static String Create_PagerLink(String sxURL, String sxVar, int iPageNumber, int iCount, int iPageSize)
        {
            String sxOutput = "<div class=\"linkbar\">";
            String sxAnchor = "<a class=\"lnk\" href=\"{0}{1}={2}\">{3}</a>&nbsp;";

            if (iPageNumber > 0)
            {
                sxOutput += String.Format(sxAnchor, sxURL, sxVar, "1", "First");
            }

            int iPageStart = ((iPageNumber - 1) * iPageSize) + 1;
            int iPageEnd = ((iPageNumber) * iPageSize);

            int iStart = iPageNumber - 5;
            int iEnd = iPageNumber + 5;

            int iTempStart = 0;
            int iTempEnd = 0;

            //int iPageCount = (int)(Math.Ceiling((double)(iCount / iPageSize))); // I DONT KNOW WHY THIS DIDN'T WORK, THE VALUE ON THE WATCH MODE IS EXACTLY RIGHT, BUT ON CODE EXECUTION IT BECAME SUCK!!!
            int iPageCount = iCount / iPageSize;
            if (iCount % iPageSize > 0)
            {
                iPageCount++;
            }

            if (iStart < 0)
            {
                iTempEnd -= iStart;
            }

            if (iEnd > iPageCount - 1)
            {
                iTempStart -= iPageCount - iEnd;
            }

            iStart -= iTempStart;
            iEnd += iTempEnd;

            for (int i = iStart; i < iEnd; i++)
            {
                if (i < 0 || i >= iPageCount) continue;

                if ((i + 1) == iPageNumber)
                {
                    sxOutput += "[" + (i + 1).ToString() + "]&nbsp;";
                }
                else
                {
                    sxOutput += String.Format(sxAnchor, sxURL, sxVar, (i + 1).ToString(), (i + 1).ToString());
                }
            }

            if (iPageNumber < iPageCount)
            {
                sxOutput += String.Format(sxAnchor, sxURL, sxVar, (iPageCount).ToString(), "Last");
            }

            sxOutput += String.Format("<div style=\"float:right;\">showing {0}-{1} from {2}</div>",
                iPageStart.ToString(), iPageEnd.ToString(), iCount.ToString()); ;

            sxOutput += "</div>";

            return sxOutput;
        }

        public static String Create_HiddenDiv(String sxControlId, String sxValue)
        {
            String sxOutput = String.Format(
                "<div id=\"{0}\" style=\"display: none;\" />{1}</div>",
                sxControlId.ReplaceQuotes(),
                sxValue);

            return sxOutput;
        }

        public static String Create_HiddenField(String sxControlId, String sxValue)
        {
            String sxOutput = String.Format(
                "<input type=\"hidden\" id=\"{0}\" value=\"{1}\" />",
                sxControlId.ReplaceQuotes(),
                sxValue.ReplaceQuotes());

            return sxOutput;
        }

        public static String Create_Button(String sxControlId, String sxJSHandlerName, String sxLabel, int iWidth)
        {
            String sxOutput = String.Empty;

            sxOutput = String.Format(
                "<input class=\"btn\" type=\"button\" {0} onclick=\"{1}\" value=\"{2}\" size=\"{3}\" style=\"width:{3}px;\" />",
                String.IsNullOrEmpty(sxControlId) ? String.Empty : "id=\"" + sxControlId.ReplaceQuotes() + "\"",
                sxJSHandlerName.ReplaceQuotes(),
                sxLabel,
                iWidth.ToString());

            return sxOutput;
        }

        public static String Create_LinkDiv(String sxControlId, String sxJSHandlerName, String sxLabel)
        {
            String sxOutput = String.Empty;

            sxOutput = String.Format(
                "<div class=\"lnk\" {0} onclick=\"{1}\">" +
                    "{2}" +
                "</div>",
                String.IsNullOrEmpty(sxControlId) ? String.Empty : "id=\"" + sxControlId.ReplaceQuotes() + "\"",
                sxJSHandlerName.ReplaceQuotes(),
                sxLabel);

            return sxOutput;
        }
        public static String Create_LinkForGrid(String sxControlId, String sxJSHandlerName, String sxLabel)
        {
            String sxOutput = String.Empty;

            sxOutput = String.Format(
                "<div class=\"lnkless\" {0} onclick=\"{1}\">" +
                    "{2}" +
                "</div>",
                String.IsNullOrEmpty(sxControlId) ? String.Empty : "id=\"" + sxControlId.ReplaceQuotes() + "\"",
                sxJSHandlerName.ReplaceQuotes(),
                sxLabel);

            return sxOutput;
        }

        public static String Create_CheckBox(String sxControlId, String sxControlName, String sxValue, bool bChecked)
        {
            String sxOutput = String.Format(
                "<input type=\"checkbox\" id=\"{0}\" name=\"{1}\" {3} style=\"width:auto;\" />" +
                "<span onclick=\"toggleCheckbox('{0}');\" class=\"clickable\" style=\"display:inline;\">" +
                "&nbsp;{2}</span>",
                sxControlId.ReplaceQuotesForJS(), 
                sxControlName.ReplaceQuotes(), 
                sxValue,
                bChecked ? "checked = \"checked\"" : String.Empty);
            return sxOutput;
        }
        public static String Create_Radio(String sxControlId, String sxControlName, String sxValue)
        {
            String sxOutput = String.Format(
                "<input type=\"radio\" id=\"{0}\" name=\"{1}\" value=\"{2}\" style=\"width:auto;\" />" +
                "<span onclick=\"toggleCheckbox('{0}');\" class=\"clickable\" style=\"display:inline;\">" +
                "&nbsp;{2}</span>",
                sxControlId.ReplaceQuotesForJS(), sxControlName.ReplaceQuotes(), sxValue.ReplaceQuotes());
            return sxOutput;
        }
        public static String Create_TextBox(String sxControlId, String sxControlName, String sxValue)
        {
            return Create_TextBox(sxControlId, sxControlName, sxValue, true);
        }
        public static String Create_TextBox(String sxControlId, String sxControlName, String sxValue, bool IsEnabled)
        {
            return Create_TextBox(sxControlId, sxControlName, sxValue, IsEnabled, TextboxType.FreeText);
        }
        public static String Create_TextBox(String sxControlId, String sxControlName, String sxValue, bool IsEnabled,
            TextboxType tpTextbox)
        {
            return Create_TextBox(sxControlId, sxControlName, sxValue, IsEnabled, tpTextbox, false);
        }
        public static String Create_TextBox(String sxControlId, String sxControlName, String sxValue, bool IsEnabled, 
            TextboxType tpTextbox, bool IsMandatory)
        {
            return Create_TextBox(sxControlId, sxControlName, sxValue, IsEnabled, tpTextbox, IsMandatory, String.Empty);
        }
        public static String Create_TextBox(String sxControlId, String sxControlName, String sxValue, bool IsEnabled, 
            TextboxType tpTextbox, bool IsMandatory, String sxCustomValue)
        {
            String sxExtraParam = String.Empty;
            String sxExtraControl = String.Empty;

            if (tpTextbox == TextboxType.FileUpload || tpTextbox == TextboxType.ImageUpload ||
                tpTextbox == TextboxType.DocumentUpload)
            {
                if (tpTextbox == TextboxType.DocumentUpload)
                {
                    sxExtraParam = String.Format("onchange=\"limitDocExtension(this.value, '{0}_{1}');\" ",
                        KControl.UPLOADBUTTON_ID, sxControlId.ReplaceQuotesForJS());
                }
                else if (tpTextbox == TextboxType.ImageUpload)
                {
                    sxExtraParam = String.Format("onchange=\"limitImageExtension(this.value, '{0}_{1}');\" ",
                        KControl.UPLOADBUTTON_ID, sxControlId.ReplaceQuotesForJS());
                }
                else if (tpTextbox == TextboxType.FileUpload)
                {
                    sxExtraParam = String.Format("onchange=\"limitAnyExtension(this.value, '{0}_{1}');\" ",
                        KControl.UPLOADBUTTON_ID, sxControlId.ReplaceQuotesForJS());
                }

                String sxUpload = String.Format(
                    "<input type=\"file\" id=\"{1}\" name=\"{0}\" {6} size=\"30\"/>" +
                    "&nbsp;&nbsp;<div id=\"{3}_{1}\" class=\"lnk\" onclick=\"submitFormbyJS('{1}','{4}','{5}');\" style=\"display:none;\">upload</div>" +
                    "<div id=\"{2}_{1}\" style=\"display:inline;\"></div>",
                    sxControlName.ReplaceQuotes(),
                    sxControlId.ReplaceQuotesForJS(),
                    KControl.UPLOADANIMATION_ID,
                    KControl.UPLOADBUTTON_ID,
                    "ASHX/FileHandler.ashx",
                    KFileHandler.Action.UPLOAD,
                    sxExtraParam);

                if (IsMandatory)
                {
                    sxUpload += "*" + Create_HiddenField("mandat_" + sxControlId.ReplaceQuotes(), KGlobal.YES);
                }

                return sxUpload;

                // file extension validation is fired at onchange event
            }

            if (tpTextbox == TextboxType.Empty)
            {
                String sxHidden = String.Format(
                        "<input type=\"hidden\" id=\"{1}\" name=\"{0}\" value=\"{2}\"/>",
                        sxControlName.ReplaceQuotes(),
                        sxControlId.ReplaceQuotes(),
                        sxValue.ReplaceQuotes());
                return sxHidden;
            }

            if (tpTextbox == TextboxType.Notes)
            {
                String sxNotes = String.Format(
                        "<textarea id=\"{1}\" name=\"{0}\" rows=\"3\">{2}</textarea>",
                        sxControlName.ReplaceQuotes(),
                        sxControlId.ReplaceQuotes(),
                        sxValue.ReplaceQuotes());
                return sxNotes;
            }

            bool IsExtraControlAfterMain = true;

            switch (tpTextbox)
            {
                case TextboxType.Integer:
                    sxExtraParam = "onkeypress=\"return onlyNumbers(this,event);\"";
                    break;
                case TextboxType.Currency:
                    sxExtraParam = "onkeypress=\"return onlyDecimals(this,event);\" onkeyup=\"formatDecimals(this);\" " +
                        "style=\"text-align:right;\"";
                    break;
                case TextboxType.Email:
                    sxExtraParam = "onblur=\"return onlyEmail(this);\"";
                    break;
                case TextboxType.PhoneNumber:
                    sxExtraParam = "onblur=\"return onlyPhone(this);\"";
                    break;
                case TextboxType.DateTime:
                    sxExtraParam = "style=\"width:90%;\" readonly=\"readonly\"";
                    sxExtraControl = String.Format("<a href=\"javascript:NewCssCal('{0}', 'ddMMMyyyy', 'Arrow', true, 24, false)\">" +
                        "<img src=\"images/cal.gif\" alt=\"Pick a date\"></a>", sxControlId.ReplaceQuotesForJS());
                    break;
                case TextboxType.Date:
                    sxExtraParam = "style=\"width:90%;\" readonly=\"readonly\"";
                    sxExtraControl = String.Format("<a href=\"javascript:NewCssCal('{0}', 'ddMMMyyyy', 'Arrow')\">" +
                        "<img src=\"images/cal.gif\" alt=\"Pick a date\"></a>", sxControlId.ReplaceQuotesForJS());
                    break;
                case TextboxType.ReadOnly:
                    sxExtraParam = "readonly=\"readonly\"";
                    break;
                case TextboxType.Rating:
                    Cached.RatingTable cachedRating = new Cached.RatingTable();
                    DataTable dtRating = cachedRating.GetRating();
                    Dictionary<String, String> dicRating = new Dictionary<String, String>();
                    foreach (DataRow dr in dtRating.Rows)
                    {
                        dicRating.Add(dr["CODE"].ToString(), dr["CODE"].ToString());
                    }
                    sxExtraControl = Create_ComboBox(sxControlId.ReplaceQuotes(), sxControlName, dicRating, sxCustomValue);
                    IsExtraControlAfterMain = false;
                    sxControlId = (sxControlId + "_notes").ReplaceQuotes();
                    break;
                case TextboxType.YesNoOption:
                    Dictionary<String, String> dicYesNo = new Dictionary<String, String>();
                    dicYesNo.Add("YES", "YES");
                    dicYesNo.Add("NO", "NO");
                    sxExtraControl = Create_ComboBox(sxControlId.ReplaceQuotes(), sxControlName, dicYesNo, sxCustomValue);
                    IsExtraControlAfterMain = false;
                    sxControlId = (sxControlId + "_notes").ReplaceQuotes();
                    break;
            }


            String sxResult = String.Format(
                "{6}<input type=\"text\" id=\"{2}\" {1} maxlength=\"255\" width=\"250px\" value=\"{0}\" {3} {4}/>{5}",
                    sxValue.ReplaceQuotes(),
                    String.IsNullOrEmpty(sxControlName) ?
                        String.Empty : String.Format("name=\"{0}\"", sxControlName.ReplaceQuotes()),
                    sxControlId.ReplaceQuotes(),
                    IsEnabled ? String.Empty : "disabled=\"true\"",
                    sxExtraParam,
                    IsExtraControlAfterMain ? sxExtraControl : String.Empty,
                    !IsExtraControlAfterMain ? sxExtraControl : String.Empty
                    );

            if (IsMandatory)
            {
                sxResult += "*" + Create_HiddenField( KControl.MANDATORY_ID + "_" + sxControlId.ReplaceQuotes(), KGlobal.YES);
            }

            return sxResult;
        }

        public static String BuildFieldSet_PairedLabel(Dictionary<String, String> dicOptions,
            Dictionary<String, String> dicInfos)
        {
            String sxOutput = String.Empty;

            if (dicInfos == null)
                return sxOutput;

            foreach (KeyValuePair<String, String> item in dicInfos)
            {
                if (dicOptions.ContainsKey(item.Key))
                    sxOutput += BuildFieldSet_PairedLabel(dicOptions[item.Key], item.Value);
                else
                    sxOutput += BuildFieldSet_PairedLabel(item.Key, item.Value);
            }

            return sxOutput;
        }

        public static String BuildFieldSet_PairedInfo(DataTable dtOptions, String sxKeyField, String sxValueField,
            String sxControlTypeField, Dictionary<String, String> dicInfos)
        {
            String sxOutput = String.Empty;

            if (dicInfos == null)
                return sxOutput;

            foreach (KeyValuePair<String, String> item in dicInfos)
            {
                DataRow[] drs = String.IsNullOrEmpty(item.Key) ? new DataRow[0]{} :
                    dtOptions.Select(String.Format("{0} = '{1}'", sxKeyField, item.Key));


                if (drs.Length > 0)
                {
                    TextboxType tpTextbox = (TextboxType)Convert.ToInt32(drs[0][sxControlTypeField]);

                    String sxControl = item.Value;

                    if (tpTextbox == TextboxType.DocumentUpload || tpTextbox == TextboxType.FileUpload ||
                        tpTextbox == TextboxType.ImageUpload)
                    {
                        int iFileUploadId = int.Parse(item.Value);
                        sxControl = CustomControls.Create_FileDownloadLink(iFileUploadId, "download");
                    }

                    sxOutput += BuildFieldSet_PairedLabel(drs[0][sxValueField].ToString(), sxControl);
                }
                else
                    sxOutput += BuildFieldSet_PairedLabel(item.Key, item.Value);
            }

            return sxOutput;
        }

        public static String Create_FileDownloadLink(int iFileUploadId, String sxLabel)
        {
            return CustomControls.Create_LinkDiv(KControl.DOWNLOADLINK_ID + iFileUploadId,
                    String.Format("downloadFile('{0}');", iFileUploadId.ToString()), 
                    "<img src=\"images/down.png\" alt=\"download this file\" />&nbsp;" + sxLabel);
        }
        public static String Create_DownloadLinkForGrid(int iFileUploadId, String sxLabel)
        {
            return CustomControls.Create_LinkForGrid(KControl.DOWNLOADLINK_ID + iFileUploadId,
                    String.Format("downloadFile('{0}');", iFileUploadId.ToString()),
                    "<img src=\"images/down.png\" alt=\"download this file\" />&nbsp;" + sxLabel);
        }
        public static String BuildFieldSet_PairedLabel(String sxLabel, String sxValue)
        {
            String sxOutput = String.Format(
               "<dt>{0}</dt>" +
               "<dd>{1}</dd>",
               String.IsNullOrEmpty(sxLabel) ? "&nbsp;" : sxLabel,
               String.IsNullOrEmpty(sxValue) ? "&nbsp;" : ": " + sxValue);

            return sxOutput;
        }

        public static String BuildEditor_FileUpload(String sxControlId, String sxHandlerName, String sxLOVFieldId,
            String sxTextboxName, TextboxType tpTextbox)
        {
            String sxOutput = String.Empty;


            sxOutput += Create_TextBox(sxControlId, sxTextboxName, String.Empty, true, tpTextbox);

            if (String.IsNullOrEmpty(sxLOVFieldId))
            {
                sxOutput += Create_HiddenField(KControl.OTF_HIDDENFIELD_LOVNAME + "_" + sxControlId, sxHandlerName);
                sxOutput += Create_HiddenField(KControl.OTF_HIDDENFIELD_ID + "_" + sxControlId, sxLOVFieldId);
            }

            return sxOutput;
        }


        public static TextboxType GetTextBoxType(String sxLOVName, String sxValue)
        {
            /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
             * THIS SHOULD BE QUERYING TO DATABASE AND RETRIEVED THE ID 
             * THERE SHOULD BE A COLUMN IN LOV VALUE LIST THAT CONTAINS THE INPUT TYPE ID
             * IT'S BETTER IF THE DATA IS CACHED
             */
            switch (sxLOVName)
            {
                case KLOV.CompanyProfile.BASICINFOTYPE:
                    Cached.CustomerInfoTypeTable ccCustInfo = new Cached.CustomerInfoTypeTable();
                    DataTable dtCustInfo = ccCustInfo.GetCustomerInfoType();

                    DataRow[] drs = String.IsNullOrEmpty(sxValue) ? 
                        new DataRow[0] :
                        dtCustInfo.Select(String.Format("ID = '{0}'", sxValue));

                    if (drs.Length > 0)
                    {
                        return (TextboxType)Convert.ToInt32(drs[0]["CONTROL_TYPE_ID"]);
                    }
                    break;
                case KLOV.CompanyProfile.CONTACTINFOTYPE:
                    Cached.ContactDataTypeTable ccContactData = new Cached.ContactDataTypeTable();
                    DataTable dtContactData = ccContactData.GetContactDataType();

                    DataRow[] drs2 = String.IsNullOrEmpty(sxValue) ?
                        new DataRow[0] :
                        dtContactData.Select(String.Format("ID = '{0}'", sxValue));

                    if (drs2.Length > 0)
                    {
                        return (TextboxType)Convert.ToInt32(drs2[0]["CONTROL_TYPE_ID"]);
                    }
                    break;
                case KLOV.UserProfile.USERDATATYPE:
                    Cached.UserDataTypeTable ccUserData = new Cached.UserDataTypeTable();
                    DataTable dtUserData = ccUserData.GetUserDataType();

                    DataRow[] drs3 = String.IsNullOrEmpty(sxValue) ?
                        new DataRow[0] :
                        dtUserData.Select(String.Format("ID = '{0}'", sxValue));

                    if (drs3.Length > 0)
                    {
                        return (TextboxType)Convert.ToInt32(drs3[0]["CONTROL_TYPE_ID"]);
                    }
                    break;
                case KFileHandler.UFT.INVITATION_ATTACHMENT:
                    return TextboxType.DocumentUpload;
                case KFileHandler.UFT.EVENT_ATTACHMENT:
                    return TextboxType.DocumentUpload;
                case KLOV.Generic.CONTACTPERSON:
                    return TextboxType.Empty;
                case KFileHandler.CD.CONFIGURATION:
                    return TextboxType.FileUpload;
                case KFileHandler.CD.DATEK:
                    return TextboxType.FileUpload;
                case KFileHandler.CV.CUSTOMER_VISIT:
                    return TextboxType.FileUpload;
                case KFileHandler.CC.COURTESY_CALL:
                    return TextboxType.FileUpload;
                case KFileHandler.CD.EVALUASI:
                    return TextboxType.FileUpload;
                case KFileHandler.UserProfile.PROFILE_PICTURE:
                    return TextboxType.ImageUpload;
                case KFileHandler.CompanyProfile.COMPANY_LOGO:
                    return TextboxType.ImageUpload;
                default: return TextboxType.FreeText;

            }
            return TextboxType.FreeText;
        }

        public static String BuildEditor_ComboBoxAndText(String sxControlId, String sxLOVName, String sxTextboxName,
            DataTable dtOptions, String sxKeyField, String sxValueField, Dictionary<String, String> dicInfos)
        {
            String sxOutput = String.Empty;
            int i = 0;


            foreach (KeyValuePair<String, String> item in dicInfos)
            {
                DataRow[] drs = String.IsNullOrEmpty(item.Key) ? 
                    new DataRow[0] :
                    dtOptions.Select(String.Format("{0} = '{1}'", sxKeyField, item.Key));

                i++;
                TextboxType tpTextbox = GetTextBoxType(sxLOVName, item.Key);
                sxOutput += BuildEditor_ComboBoxAndText(sxControlId + "_" + i.ToString(), sxLOVName, sxTextboxName, drs.Length > 0 ? drs[0][sxValueField].ToString() : String.Empty, item.Key, item.Value, tpTextbox);
            }

            return sxOutput;
        }

        public static String BuildEditor_ComboBoxAndText(String sxControlId, String sxLOVName, String sxTextboxName,
            Dictionary<String, String> dicOptions, Dictionary<String, String> dicInfos)
        {
            String sxOutput = String.Empty;
            int i = 0;


            foreach (KeyValuePair<String, String> item in dicInfos)
            {
                i++;
                TextboxType tpTextbox = GetTextBoxType(sxLOVName, item.Key);
                sxOutput += BuildEditor_ComboBoxAndText(sxControlId + "_" + i.ToString(), sxLOVName, sxTextboxName, dicOptions[item.Key], item.Key, item.Value, tpTextbox);

            }

            return sxOutput;
        }

        public static String BuildEditor_ComboBoxAndText(String sxControlId, String sxLOVName, String sxControlName,
            String sxOptionLabel, String sxKey, String sxValue)
        {
            return BuildEditor_ComboBoxAndText(sxControlId, sxLOVName, sxControlName, sxOptionLabel, sxKey, sxValue, 
                TextboxType.FreeText);
        }
        public static String BuildEditor_ComboBoxAndText(String sxControlId, String sxLOVName, String sxControlName, 
            String sxOptionLabel, String sxKey, String sxValue, TextboxType tpTextbox)
        {
            return BuildEditor_ComboBoxAndText(sxControlId, sxLOVName, sxControlName, sxOptionLabel, sxKey, sxValue, tpTextbox, null);
        }
        public static String BuildEditor_ComboBoxAndText(String sxControlId, String sxLOVName, String sxControlName, 
            String sxOptionLabel, String sxKey, String sxValue, TextboxType tpTextbox, String sxCustomParam)
        {
            String sxOutput = String.Empty;

            bool IsNewForm = String.IsNullOrEmpty(sxOptionLabel) && String.IsNullOrEmpty(sxKey) && String.IsNullOrEmpty(sxValue);

            String sxDropDown = CustomControls.Create_OTFComboBox(sxControlId, sxLOVName, sxOptionLabel, sxKey, tpTextbox, sxCustomParam, null);


            String sxTextbox = String.Empty;

            if ((tpTextbox == TextboxType.FileUpload || tpTextbox == TextboxType.ImageUpload ||
                tpTextbox == TextboxType.DocumentUpload) && !String.IsNullOrEmpty(sxValue))
            {
                sxTextbox = Build_FileUploadResult(sxControlId, sxValue, sxLOVName, sxControlName, sxValue, "download");
            }
            else
            {
                sxTextbox = Create_TextBox(sxControlId, sxControlName, sxValue, !IsNewForm, tpTextbox);
            }

            sxOutput = String.Format(
                "<dt>{0}</dt>" +
                "<dd>: {1}</dd>",
                sxDropDown,
                sxTextbox);

            return sxOutput;
        }

        public static String Build_FileUploadResult(String sxControlId, String sxLOVFieldId, String sxHandlerName,
            String sxControlName, String sxValue, String sxFilename)
        {
            return Build_FileUploadResult(sxControlId, sxLOVFieldId, sxHandlerName, sxControlName, sxValue,
                sxFilename, true);
        }
        public static String Build_FileUploadResult(String sxControlId, String sxLOVFieldId, String sxHandlerName,
            String sxControlName, String sxValue, String sxFilename, bool IsNeedDeleteButton)
        {
            String sxOutput = String.Empty;

            if (String.IsNullOrEmpty(sxLOVFieldId))
            {
                sxOutput = String.Format(
                    "<div class=\"lnk\" onclick=\"downloadUploaded('{2}');\">" +
                    "<img src=\"images/down.png\" alt=\"download this file\" /> {3}" +
                    "</div>" +
                    "{8}" +
                    "<input type=\"hidden\" id=\"{2}\" {1} value=\"{0}\"/>" +
                    "<input type=\"hidden\" id=\"{4}_{2}\" value=\"{7}\"/>" +
                    "<input type=\"hidden\" id=\"{5}_{2}\" value=\"{7}\"/>" +
                    "<input type=\"hidden\" id=\"{6}_{2}\" value=\"\"/>",
                    sxValue.ReplaceQuotes(),
                    String.IsNullOrEmpty(sxControlName) ? String.Empty : String.Format("name=\"{0}\"", sxControlName),
                    sxControlId.ReplaceQuotesForJS(),
                    sxFilename,
                    KControl.OTF_HIDDENFIELD_LOVNAME,
                    KControl.OTF_HIDDENFIELD_ID,
                    KControl.OTF_HIDDENFIELD_LOVDATATYPE,
                    sxHandlerName.ReplaceQuotes(),
                    IsNeedDeleteButton ?
                        String.Format("&nbsp;|&nbsp;<div class=\"lnk\" onclick=\"deleteUploaded('{0}');\">delete</div>", 
                        sxControlId.ReplaceQuotesForJS()) :
                        String.Empty);
            }
            else
            {
                sxOutput = String.Format(
                    "<div class=\"lnk\" onclick=\"downloadUploaded('{2}');\">" +
                    "<img src=\"images/down.png\" alt=\"download this file\" /> {3}" +
                    "</div>" +
                    "{4}" +
                    "<input type=\"hidden\" id=\"{2}\" {1} value=\"{0}\"/>",
                    sxValue.ReplaceQuotes(),
                    String.IsNullOrEmpty(sxControlName) ?
                        String.Empty : String.Format("name=\"{0}\"", sxControlName.ReplaceQuotes()),
                    sxControlId.ReplaceQuotesForJS(),
                    sxFilename,
                    IsNeedDeleteButton ?
                        String.Format("&nbsp;|&nbsp;<div class=\"lnk\" onclick=\"deleteUploaded('{0}');\">delete</div>",
                        sxControlId.ReplaceQuotesForJS()) :
                        String.Empty);
            }

            return sxOutput;
        }

        public static String BuildEditor_LabelAndText(String sxControlId, String sxControlName, String sxLabel, String sxValue) 
        {
            return BuildEditor_LabelAndText(sxControlId, sxControlName, sxLabel, sxValue, TextboxType.FreeText);
        }
        public static String BuildEditor_LabelAndText(String sxControlId, String sxControlName, String sxLabel, String sxValue, TextboxType tpTextBox)
        {
            return BuildEditor_LabelAndText(sxControlId, sxControlName, sxLabel, sxValue, tpTextBox, false);
        }
        public static String BuildEditor_LabelAndText(String sxControlId, String sxControlName, String sxLabel, String sxValue, TextboxType tpTextBox, bool IsMandatory)
        {
            return BuildEditor_LabelAndText(sxControlId, sxControlName, sxLabel, sxValue, tpTextBox, IsMandatory, String.Empty);
        }
        public static String BuildEditor_LabelAndText(String sxControlId, String sxControlName, String sxLabel, String sxValue, TextboxType tpTextBox, bool IsMandatory, String sxCustomValue)
        {
            String sxTextBox = Create_TextBox(
                sxControlId.ReplaceQuotes(), sxControlName.ReplaceQuotes(), sxValue.ReplaceQuotes(), true, tpTextBox, IsMandatory, sxCustomValue);
            
            String sxOutput = String.Format(
                "<dt>{0}</dt>" +
                "<dd>: {1}</dd>",
                sxLabel,
                sxTextBox);

            return sxOutput;
        }

        public static String BuildEditor_PopupNewLOVItem(String sxControlId, String sxLOVName, String sxValue, bool IsNeedControlType)
        {
            String sxOutput = String.Empty;

            Cached.ControlTypeTable ccControl = new Cached.ControlTypeTable();

            DataTable dtControlTypes = ccControl.GetControlTypeList();

            String sxLeft = IsNeedControlType ? Create_ComboBox(dtControlTypes, KControl.LOVPOPSELECT_ID + "_" + sxControlId,
                KControl.DROPDOWN_ID, String.Empty, "ID", "HINT") : "Nilai baru";

            String sxDef = BuildEditor_LabelAndText(KControl.LOVPOPINPUT_ID + "_" + sxControlId,
                KControl.INPUT_ID, sxLeft, sxValue);

            sxOutput = String.Format(
                "<div id=\"{1}_{0}\" class=\"popLOV\">" +
                    "<fieldset class=\"m_fs_border\" id=\fs_lov_{0}\">" +
                        "<legend>" +
                            "<a class=\"lnk\" href=\"javascript:toggle('lov_{0}');\">Add New LOV Value</a>" +
                        "</legend>" +
                        "<dl class=\"m_fs\"><div id=\"div_lov_{0}\">{2}</div></dl>" +
                        "<div id=\"lnkdscd_lov_{0}\" class=\"lnk\" style=\"float: right; margin-left: 5px; margin-right: 15px;\"" +
                            " onclick=\"closePopupLayer();\">cancel</div>" +
                        "<div id=\"lnkedit_lov_{0}\" class=\"lnk\" style=\"float: right; margin-left: 5px; margin-right: 5px;\"" +
                            " onclick=\"insert2LOV('{0}');\">save</div>" +
                    "</fieldset>" +
                "</div>",
                sxControlId.ReplaceQuotesForJS(),
                KControl.LOVPOPFORM_ID,
                sxDef);
            return sxOutput;
        }
    }
}